#ifndef SOCKET_H
#define SOCKET_H

#include <sys/socket.h>
#include <sys/types.h>
#include "InetAddress.h"

class Socket {
    static const int MAX_LISTEN_NUM = 1024;
public:
    //直接生成一个可用的监听Socket
    Socket(uint16_t port = 8080);
    Socket(int sockFd) : m_fd(sockFd) {};
    ~Socket();
    void bindAddress(InetAddress& localAddr);
    void listen(int num = MAX_LISTEN_NUM);
    int accept(InetAddress* peerAddr = nullptr);

    void setReuseAddr(bool on);
    void setReusePort(bool on);
    void setKeepAlive(bool on);
private:
    int m_fd;
};

#endif